﻿#pragma once

#include <QObject>
#include "QNetworkAccessManager"

#define DOWNLOAD_FILE_SUFFIX    "_tmp"
#define DOWNLOAD_FOLDER    "temp"
class UpdateWorker : public QObject
{
	Q_OBJECT

public:
    UpdateWorker(QObject *parent= nullptr);
    ~UpdateWorker();

public slots:
    void onInit();
    void onQuit();
    void onUpdateFile(QString url, QString dstPath);
private:
    bool saveToDisk(const QString& filename, QIODevice* reply);
    bool updateFile(QString src, QString dst);

signals:
    void sigDownloadProgress(qint64 receive, qint64 total);
    void sigDownloadFinished(QString filename, bool success);

private:
    QNetworkAccessManager* mNetWork;
    QString downloadFolder;
};
